package com.agent.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.agent.mapper.AsFunctionMapper;
import com.agent.pojo.AsFunction;
import com.agent.pojo.AsFunctionExample;
import com.agent.pojo.AsFunctionExample.Criteria;
import com.agent.service.AsFunctionService;
@Service
public class AsFunctionServiceImpl implements AsFunctionService {
	@Autowired
	private AsFunctionMapper asFunctionMapper;
	@Override
	public List<HashMap<String, Object>> queryFunctions() {
		// TODO Auto-generated method stub
		List<HashMap<String, Object>> list=new ArrayList<HashMap<String, Object>>();
		AsFunctionExample example=new AsFunctionExample();
		Criteria criteria=example.createCriteria();
		criteria.andParentidEqualTo(0);
		List<AsFunction> functions=asFunctionMapper.selectByExample(example);
		for(AsFunction function : functions){
			HashMap<String, Object> li=new HashMap<String, Object>();
			li.put("id", function.getId());
			li.put("functioncode", function.getFunctioncode());
			li.put("functionname", function.getFunctionname());
			li.put("creationtime", function.getCreationtime());
			li.put("createdby", function.getCreatedby());
			li.put("lastupdatetime", function.getLastupdatetime());
			li.put("funcurl", function.getFuncurl());
			li.put("isstart", function.getIsstart());
			li.put("parentid", function.getParentid());
			AsFunctionExample cexample=new AsFunctionExample();
			cexample.createCriteria().andParentidEqualTo(function.getId().intValue());
			List<AsFunction> children=asFunctionMapper.selectByExample(cexample);
			li.put("children", children);
			list.add(li);
		}
		return list;
	}

}
